/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package studenttrack.session;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import stException.BadLoginException;
import stException.ModuleCodeAlreadyAssignedException;
import stException.NotCoordinatorException;
import stException.NotLoggedInException;
import studenttrack.entity.ModuleI;
import studenttrack.entity.ModuleInterface;

/**
 *
 * @author tg227
 */
@Stateless
public class StaffSession implements StaffSessionRemote {
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @Override
    public void login(String emailID, String password) throws BadLoginException{

    }
    @Override
    public List<ModuleInterface> getCoordinatedModules() throws NotLoggedInException{
        ArrayList<ModuleInterface> al = new ArrayList<ModuleInterface>();
        return al;
    }
    @Override
    public void setModuleDetails(ModuleInterface module) throws NotLoggedInException, NotCoordinatorException{

    }

    @PersistenceContext
        EntityManager manager;
    
    
    @Override
    public void addModule(ModuleInterface module) throws NotLoggedInException, ModuleCodeAlreadyAssignedException{

        String sql;
        //sql = "INSERT INTO ModuleI (id, modname) VALUES(ECM3002, JavaDBAdvanced);";
        //manager.createQuery(sql);
        //System.out.println("ran query: " + sql);

//        sql = "INSERT INTO ModuleI (modname) VALUES('java')";
//        List<ModuleI> modList = manager.createNativeQuery(sql).getResultList();
//        System.out.println("ran query: " + sql);
//        System.out.println("results:");
//        int i = 0;
//        while(i < modList.size()){
//        System.out.println(modList.get(i).getCode() + " " + modList.get(i).getName());
//        i++;

//        }
        ModuleI mod = new ModuleI();
        mod.setCode("ECM3004");
        mod.setName("Persistant Learning");
        manager.persist(mod);

    }
    
    public void addTestModule() throws ModuleCodeAlreadyAssignedException, NotLoggedInException{
        ModuleI m = new ModuleI();
        m.setCode("ECM3001");
        m.setName("JavaDB basics");
        addModule((ModuleInterface) m);
    }
}

    

